import type { DescData } from '@arco-design/web-vue/es/descriptions/interface'
import axios from 'axios'
import qs from 'query-string'

export interface CategoryRecord {
    id: number,
    name: string | null,
    sort: number,
    visibility: boolean
}

export interface PageQuery {
    current: number
    pageSize: number
    name?: string
}

export interface CategoryPageRes {
    list: CategoryRecord[]
    total: number
}

export interface CategoryDetail extends CategoryRecord {
    id: number,
    name: string | null,
    sort: number,
    visibility: boolean
}

export function getCategoryDetail(id: number) {
    return axios.get<CategoryDetail>(`/api/category/${id}`)
}

// 编辑分类信息
export function createCategory(data: CategoryDetail) {
    return axios.put('/api/category/add', data)
}

// 编辑分类信息
export function updateCategory(data: CategoryDetail) {
    return axios.put('/api/category', data)
}

// 使分类可见/不可见
export function toggleCategoryStatus(id: number) {
    return axios.put(`/api/category/enable/${id}`)
}


// 删除分类
export function deleteCategory(ids: number[]) {
    return axios.delete('/api/category', {
        data: ids
    })
}

export function queryCategoryPage(params: PageQuery) {
    return axios.get<CategoryPageRes>('/api/category/page', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj)
        },
    })
}